<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .container {
      width: 400px;
      height: 200px;
      background: #000;
      /* 触发BFC */
      overflow: scroll;
    }

    .content {
      /* width要和浮动元素相等 */
      width: 200px;
      height: 200px;
      background: yellow;
      margin: 100px auto;
    }

    .float {
      float: left;
      width: 100px;
      height: 100px;
      background: #161;
    }
  </style>
</head>

<body>
  <div class="container">
    <div class="content">
      <div class="float">
        我是浮动元素
      </div>
    </div>
  </div>
</body>

</html>